#include"Calculator.hpp"
#include"Parser.hpp"
#include"TcpServer.hpp"
#include"Logger.hpp"
#include"Deamon.hpp"

void Usage(std::string proc)
{
    std::cerr << "Usage: "<< proc << " serverport" <<std::endl; 
}

//./server port
int main(int argc , char* argv[])
{
    if(argc !=2)
    {
        Usage("argv[0]");
        return 0;
    }

    //守护进程
    Deamon();

    // EnableConsoleLogStrategy();
    EnableFileLogStrategy();

    uint16_t port = std::stoi(argv[1]);

    //任务处理
    std::unique_ptr<Calculator> cal = std::make_unique<Calculator>();

    //协议层面，对于请求的处理，返回应答
    std::unique_ptr<Parser> parse = std::make_unique<Parser>(
        [&cal](Request& req)->Responce{
            return cal->Exec(req);
        });

    //网络层面，从网络中获取数据
    std::unique_ptr<TcpServer> svr = std::make_unique<TcpServer>(port,
    [&parse]( std::string& inbuffer)->std::string{
        return parse->Parse(inbuffer);}
    );
    svr->Run();
    return 0;
}